package com.prs.crm.action.receipt;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.receipt.ReceiptFlow;
import com.prs.crm.domain.receipt.ReceiptFlowType;
import com.prs.crm.service.receipt.ReceiptFlowService;
import com.prs.crm.service.receipt.ReceiptFlowTypeService;

public class ReceiptFlowAction  extends BaseAction{

	private static final long serialVersionUID = 1L;
	private ReceiptFlow receiptFlow;
	private ReceiptFlowService receiptFlowService;
	private PaginationSupport pagination;
	private Integer[] ids;
	private List<ReceiptFlowType> receiptFlowType;
	private ReceiptFlowTypeService receiptFlowTypeService;
	public ReceiptFlow getReceiptFlow() {
		return receiptFlow;
	}
	public void setReceiptFlow(ReceiptFlow receiptFlow) {
		this.receiptFlow = receiptFlow;
	}
	public ReceiptFlowService getReceiptFlowService() {
		return receiptFlowService;
	}
	public void setReceiptFlowService(ReceiptFlowService receiptFlowService) {
		this.receiptFlowService = receiptFlowService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public List<ReceiptFlowType> getReceiptFlowType() {
		return receiptFlowType;
	}
	public void setReceiptFlowType(List<ReceiptFlowType> receiptFlowType) {
		this.receiptFlowType = receiptFlowType;
	}
	public ReceiptFlowTypeService getReceiptFlowTypeService() {
		return receiptFlowTypeService;
	}
	public void setReceiptFlowTypeService(
			ReceiptFlowTypeService receiptFlowTypeService) {
		this.receiptFlowTypeService = receiptFlowTypeService;
	}
	@Action("listReceiptFlow")
	public String listReceiptFlow(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ReceiptFlow.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getReceiptFlowService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editReceiptFlow")
	public String editReceiptFlow(){
		this.receiptFlowType=this.getReceiptFlowTypeService().getAllreceiptFlowType();
		return SUCCESS;
	}
	
	@Action(value="saveReceiptFlow",results={
			@Result(name="success",type="redirect",location="listReceiptFlow"),
			@Result(name="error",type="chain",location="editReceiptFlow")
	})
	public String saverReceiptFlow(){
		this.getReceiptFlowService().save(receiptFlow);
		return SUCCESS;
	}
	
	@Action(value="removeReceiptFlow",results={
			@Result(name="success",type="redirect",location="listReceiptFlow"),
			@Result(name="error",type="chain",location="listReceiptFlow")
	})
	public String removeReceiptFlow(){
		if (ids==null) {
			this.addActionError("请选择一行");
			return ERROR;
		}
		this.getReceiptFlowService().batchRemove(ids);
		return SUCCESS;
	}
}
